/***********************************************
 * A class to test database functionality  
 * @author Brian Renzenbrink
 ***********************************************/

package tests;

import java.sql.Date;
import java.sql.ResultSet;
import database.DB_connection;
import database.DB_creation;

public class DB_test{
	
	public static void main(String args[]){
		test_DB_creation();
	}
	
	public static void test_DB_connection(){
		DB_connection dbConn = new DB_connection();
		System.out.println("Testing the DB_Connection class.");
		System.out.println("URL: " + dbConn.getUrl());
		System.out.println("Connection: " + dbConn.getConn());
		
		ResultSet rs;
		rs = dbConn.executeCurrentStatement("SELECT * from Weightlifting, Exercise WHERE Weightlifting.exerciseID = Exercise.EID ORDER BY daterecorded");
		
		System.out.println("Display all results:");
		int count = 1;
		try{
			while(rs.next()){
				Date date = rs.getDate("daterecorded");
				String str = rs.getString("Exercise");
				System.out.println(count + ":\tDate= " + date.toString() + "\tExercise = " + str);
				count++;
			}//end while loop
			dbConn.closeConnection();
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	public static void test_DB_creation(){
		//Test the initialization function		
		//DB_creation.initialize("root", "xenogears");
	   
		test_DB_connection();
	}
	
}